﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using vroom.db.model;
using vroom.wcf.service.common;


namespace vroom.wcf.dal
{
	public class PosDataAccess
	{

		public object[] GetPositions (string tableName, string userName, DateTime effectiveDate)
		{
			return GetPositions(effectiveDate);
		}


		public Position[] GetPositions(DateTime effectiveDate)
		{
            using (ReportingEntities entities = new ReportingEntities())
			{
				var res = entities.Position.Where(p => p.Date == effectiveDate);
                Position[] results = res.ToArray<Position>();
				return results;
			}
		}




		public Bucket[] GetBucketedPositions(DateTime effectiveDate)
		{
            using (ReportingEntities entities = new ReportingEntities())
			{
				var res = entities.Bucket.Where(p => p.Date == effectiveDate);
                Bucket[] results = res.ToArray<Bucket>();
				return results;
			}
		}


		public ITableState[] GetTableStateInfo()
		{
            using (ReportingEntities entities = new ReportingEntities())
			{
				IEnumerable<ITableState> tables = entities.TableState.Select(p => new vroom.wcf.service.common.TableState()
																							{
																								TableName    = p.TableName,
																								TableDate    = p.TableDate,
																								TableUpdated = p.tableUpdated
																							});
				return tables.ToArray();
			}
		}
	}
}
